with f as (
  select *
       ,row_number() over(partition by id order by update_time desc) as rank
  from jms_ods.arbitration
    where dt between date_add('{{ execution_date | cst_ds }}',-150)
         and '{{ execution_date | cst_ds }}'
             and date(create_time) between date_add('{{ execution_date | cst_ds }}',-150)
             and '{{ execution_date | cst_ds }}'
)
insert overwrite table jms_dwd.dwd_arbitration_base_dt partition(dt)
  select
        id
       ,code
       ,waybill_no
       ,goods_type_id
       ,goods_type_code
       ,goods_type_name
       ,goods_name
       ,goods_value
       ,first_type_id
       ,first_type_code
       ,first_type
       ,second_type_id
       ,second_type_code
       ,second_type
       ,exception_desc
       ,status
       ,responsibility_reply_status
       ,responsibility_confirm_status
       ,arbitration_reply_status
       ,appeal_reply_status
       ,responsibility_reply_opinion
       ,process_type
       ,process_user_id
       ,process_user_code
       ,process_user_name
       ,process_network_id
       ,process_network_code
       ,process_network_name
       ,arbitration_auto_receive_time
       ,arbitration_receive_time
       ,assign_time
       ,arbitration_award_network_id
       ,arbitration_award_network_code
       ,arbitration_award_network_name
       ,arbitrator_id
       ,arbitrator_code
       ,arbitrator_name
       ,arbitration_award_time
       ,edit_count
       ,edit_time
       ,return_user_id
       ,return_user_code
       ,return_user_name
       ,return_opinion
       ,return_time
       ,appeal_decision_network_id
       ,appeal_decision_network_code
       ,appeal_decision_network_name
       ,appeal_adjudicator_id
       ,appeal_adjudicator_code
       ,appeal_adjudicator_name
       ,is_appeal_fee
       ,appeal_time
       ,appeal_assign_time
       ,appeal_decision_time
       ,arbitration_auto_close_time
       ,closing_time
       ,payable_amount_total
       ,handling_fee_total
       ,award_amount_total
       ,create_by
       ,create_by_code
       ,create_by_name
       ,create_network_id
       ,create_network_code
       ,create_network_name
       ,create_parent_id
       ,create_parent_code
       ,create_parent_name
       ,create_time
       ,delay_day
       ,restart_count
       ,finance_status
       ,end_status
       ,delay_adju_status
       ,arbitration_remark
       ,update_by
       ,update_by_code
       ,update_by_name
       ,update_time
       ,collect_time
       ,verify_time
       ,shipment_no
       ,adjudications
       ,networks
       ,process_records
       ,is_appeal
           ,is_closed_last
           ,third_remark
           ,order_source_code
           ,order_source_name
           ,channel
           ,is_vip
           ,is_renew_pod_track
           ,arrival_time
           ,redundancy
           ,audit_status
           ,first_comp_network_id
           ,first_comp_network_code
           ,first_comp_network_name
           ,first_comp_parent_id
           ,first_comp_parent_code
           ,first_comp_parent_name
           ,second_comp_network_id
           ,second_comp_network_code
           ,second_comp_network_name
           ,second_comp_parent_id
           ,second_comp_parent_code
           ,second_comp_parent_name
           ,first_resp_network_id
           ,first_resp_network_code
           ,first_resp_network_name
           ,first_resp_parent_id
           ,first_resp_parent_code
           ,first_resp_parent_name
           ,first_confirm_status
           ,second_resp_network_id
           ,second_resp_network_code
           ,second_resp_network_name
           ,second_resp_parent_id
           ,second_resp_parent_code
           ,second_resp_parent_name
           ,second_confirm_status
           ,third_resp_network_id
           ,third_resp_network_code
           ,third_resp_network_name
           ,third_resp_parent_id
           ,third_resp_parent_code
           ,third_resp_parent_name
           ,third_confirm_status
           ,four_resp_network_id
           ,four_resp_network_code
           ,four_resp_network_name
           ,four_resp_parent_id
           ,four_resp_parent_code
           ,four_resp_parent_name
           ,four_confirm_status
           ,five_resp_network_id
           ,five_resp_network_code
           ,five_resp_network_name
           ,five_resp_parent_id
           ,five_resp_parent_code
           ,five_resp_parent_name
           ,five_confirm_status
           ,station_name
           ,business_name
           ,is_value_prove
           ,is_public_distribution_network
           ,arb_source
           ,express_type_id
           ,express_type_code
           ,express_type_name
           ,arb_behavior
           ,customer_code
           ,customer_name
           ,`is_first_error` -- '是否首次错误 1是，2否',
           ,`first_error_desc` -- '错误描述',
           ,`is_package_inner_lost` -- '是否包内件遗失 1：是, 2：否',
           ,`first_resp_network_type_id` -- '第一个责任网点类型id',
           ,`second_resp_network_type_id` -- '第二个责任网点类型id',
           ,`third_resp_network_type_id` -- '第三个责任网点类型id',
           ,`four_resp_network_type_id` -- '第四个责任网点类型id',
           ,`five_resp_network_type_id` -- '第五个责任网点类型id',
           ,`zy_dynamic_scan_time` --  '异常时间(自有平台实际扫描时间)',
           ,`resp_network_num` --  '责任网点个数'
       ,date(create_time) as dt
 from f
where rank = 1
distribute by dt,abs(hash(id))%4;